unit Unit2;

interface

uses
  Windows, SysUtils, Classes, Controls, Forms, StdCtrls, ComCtrls,
  untPasScriptCompile;

type
  TForm2 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Memo1: TMemo;
    btnCompile: TButton;
    btnRun: TButton;
    PageControl2: TPageControl;
    TabSheet6: TTabSheet;
    TabSheet7: TTabSheet;
    TabSheet8: TTabSheet;
    TabSheet9: TTabSheet;
    edtVars: TMemo;
    edtConsts: TMemo;
    edtMethods: TMemo;
    edtPCodes: TMemo;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    TabSheet5: TTabSheet;
    TabSheet10: TTabSheet;
    Memo2: TMemo;
    Memo3: TMemo;
    Memo4: TMemo;
    Memo5: TMemo;
    Memo6: TMemo;
    TabSheet11: TTabSheet;
    Memo7: TMemo;
    TabSheet12: TTabSheet;
    Memo8: TMemo;
    TabSheet13: TTabSheet;
    Memo9: TMemo;
    Button1: TButton;
    procedure btnCompileClick(Sender: TObject);
    procedure btnRunClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FCPU: TVMCPU;
    FMemo: TMemo;

  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.btnCompileClick(Sender: TObject);
begin
  if FMemo = nil then
    exit;

  FCPU := TAnalyProgram.Analy(FMemo.Text);

  if FCPU <> nil then
  begin
    edtPCodes.Text := FCPU.VMPCodeList.Text;
    edtVars.Text := FCPU.VarList.Text;
    edtConsts.Text := FCPU.ConstVarList.Text;
    edtMethods.Text := FCPU.MethodList.Text;
  end;
end;

procedure TForm2.btnRunClick(Sender: TObject);
var
  t: Cardinal;
begin
  t := GetTickCount;
  FCPU.Run;

  Caption := IntToStr(GetTickCount - t);

  edtVars.Text := FCPU.VarList.Text;
  edtConsts.Text := FCPU.ConstVarList.Text;
end;

procedure TForm2.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage = TabSheet1 then
  begin
    FMemo := Memo1;
  end;

  if PageControl1.ActivePage = TabSheet2 then
  begin
    FMemo := Memo2;
  end;

  if PageControl1.ActivePage = TabSheet3 then
  begin
    FMemo := Memo3;
  end;

  if PageControl1.ActivePage = TabSheet4 then
  begin
    FMemo := Memo4;
  end;

  if PageControl1.ActivePage = TabSheet5 then
  begin
    FMemo := Memo5;
  end;

  if PageControl1.ActivePage = TabSheet10 then
  begin
    FMemo := Memo6;
  end;

  if PageControl1.ActivePage = TabSheet11 then
  begin
    FMemo := Memo7;
  end;

  if PageControl1.ActivePage = TabSheet12 then
  begin
    FMemo := Memo8;
  end;
  if PageControl1.ActivePage = TabSheet13 then
  begin
    FMemo := Memo9;
  end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  PageControl1Change(nil);
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  Caption := 'asdf';
end;

procedure TForm2.Button1Click(Sender: TObject);
var
  t: Cardinal;
begin
  t := GetTickCount;
  FCPU.Resume;
  t := GetTickCount - t;
  Caption := inttostr(t);

  edtVars.Text := FCPU.VarList.Text;
  edtConsts.Text := FCPU.ConstVarList.Text;
end;

end.
